<%--
  Created by IntelliJ IDEA.
  User: Lanan
  Date: 2017/12/28 0028
  Time: 9:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>微信公众号模板消息</title>
</head>
<body>

<script type="text/javascript">
    var wechatPublicMessageTemplateDataGrid;
    $(function () {
        wechatPublicMessageTemplateDataGrid = $("#wechatPublicMessageTemplateDataGrid").datagrid({
            url:"${path}/wechat/public/number/message/template/list.do",
            fit:true,
            idField:'id',
            rownumbers:true,
            pagination:true,
            fitColumns:true,
            singleSelect:true,
            frozenColumns : [[{
                title : 'ID',
                field : 'id',
                align : 'center',
                checkbox:true
            }]],
            columns : [[{
                title : '模板ID',
                field : 'templateId',
                align : 'center'
            }, {
                title : '模板标题',
                field : 'title',
                align : 'center',
            }, {
                title : '模板内容',
                field : 'content',
                align : 'center',
                width : '300px',
            }, {
                field : 'action',
                align : 'center',
                title : '操作',
                width : '200px',
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/wechat/public/number/message/template/update.do">
                    str += $.formatString('<a href="javascript:void(0)" class="resource-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="updateWechatPublicMessageTemplate(\'{0}\');" >编辑</a>',index);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/wechat/public/number/message/template/delete.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="resource-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteWechatPublicMessageTemplate(\'{0}\');" >删除</a>', index);
                    </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.resource-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.resource-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#wechatPublicMessageTemplateDataGridToolbar'
        })
    })

    function insertWechatPublicMessageTemplate() {
        flag = 'add';
        $("#message_template_form").form("clear");
        $("#message_template_dialog").dialog({title: "添加微信公众号模板消息"});
        $("#message_template_dialog").dialog("open");
    }

    function updateWechatPublicMessageTemplate(index) {
        wechatPublicMessageTemplateDataGrid.datagrid('selectRow',index);  //选中
        var row = wechatPublicMessageTemplateDataGrid.datagrid('getSelected');      //获取选中行

        if (row == null) {
            $.messager.alert("提示","请选择要修改的消息模板！","info");
            return;
        }
        flag = 'update';
        $("#message_template_form").form("load", row);
        $("#message_template_dialog").dialog({title: "修改微信公众号模板消息"});
        $("#message_template_dialog").dialog("open");
    }

    function submitMessageTemplate() {
        var url = "";
        var msg = "";
        if (flag == 'add') {
            msg = "添加";
            url = "${path}/wechat/public/number/message/template/insert.do"
        } else {
            msg = "修改";
            url = "${path}/wechat/public/number/message/template/update.do"
        }

        lananUpdateOrInsert(msg, url, "message_template_form", "message_template_dialog", "wechatPublicMessageTemplateDataGrid")
    }

    function deleteWechatPublicMessageTemplate(index) {
        wechatPublicMessageTemplateDataGrid.datagrid('selectRow',index);  //选中
        lananDelete("wechatPublicMessageTemplateDataGrid", "您确定要删除该模板消息", "${path}/wechat/public/number/message/template/delete.do")
    }

</script>

<!-- 数据表格 begin -->
<table id="wechatPublicMessageTemplateDataGrid"></table>

<%--tool bar--%>
<div id="wechatPublicMessageTemplateDataGridToolbar">
    <shiro:hasPermission name="/wechat/public/number/message/template/insert.do">
        <a onclick="insertWechatPublicMessageTemplate()" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'l-btn-icon fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
</div>

<div class="easyui-dialog" id="message_template_dialog" data-options="closed:true,modal:true,width:400,height:260">
    <form id="message_template_form" method="post">
        <table align="center" width="100%" style="margin-top: 20px" cellpadding="4">
            <input hidden="hidden" name="id"/>
            <tr>
                <td width="35%" align="right"><label>模板ID:</label></td>
                <td width="65%" align="left"><input name="templateId" class="easyui-validatebox" data-options="required:true,missingMessage:'请输入模板ID'"/></td>
            </tr>
            <tr>
                <td align="right"><label>模板标题:</label></td>
                <td align="left"><input name="title" class="easyui-validatebox" data-options="required:true,missingMessage:'请输入模板标题'"/></td>
            </tr>
            <tr id="contentInfo">
                <td align="right"><label>模板内容:</label></td>
                <td colspan="2" align="left">
                    <textarea name="content" class="easyui-validatebox" data-options="missingMessage:'请输入模板内容',required:true" style="height:75px;width: 150px"></textarea>
                </td>
            </tr>
        </table>

        <div style="margin-top: 30px;text-align: center">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'", onclick="submitMessageTemplate()">提交</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'", onclick="$('#message_template_dialog').dialog('close')">取消</a>
        </div>
    </form>
</div>

</body>
</html>
